package com.yw.smartcity_study;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;

import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.yw.smartcity_study.fragment.HomeFragment;
import com.yw.smartcity_study.fragment.JZFPFragment;
import com.yw.smartcity_study.fragment.NewsFragment;
import com.yw.smartcity_study.fragment.PersonFragment;
import com.yw.smartcity_study.fragment.ServiceFragment;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class MainActivity extends AppCompatActivity {

    private ViewPager viewPage;
    private BottomNavigationView navigation;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        viewPage = (ViewPager) findViewById(R.id.viewPage);

        navigation = (BottomNavigationView) findViewById(R.id.navigation);

        List<Fragment> datas = new ArrayList();
        datas.add(new HomeFragment());
        datas.add(new ServiceFragment());
        datas.add(new JZFPFragment());
        datas.add(new NewsFragment());
        datas.add(new PersonFragment());

        viewPage.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @NonNull
            @Override
            public Fragment getItem(int position) {
                return datas.get(position);
            }

            @Override
            public int getCount() {
                return datas.size();
            }
        });

        viewPage.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
            }
        });


        navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId()){
                    case R.id.home_menu:
                        viewPage.setCurrentItem(0);
                        break;
                    case R.id.service_menu:
                        viewPage.setCurrentItem(1);
                        break;
                    case R.id.jzfp_menu:
                        viewPage.setCurrentItem(2);
                        break;
                    case R.id.news_menu:
                        viewPage.setCurrentItem(3);
                        break;
                    case R.id.person_menu:
                        viewPage.setCurrentItem(4);
                        break;
                }
                return true;
            }
        });

    }
}